// ==UserScript==
// @name           Spockholm Mafia Toolbar GoogleCode
// @namespace      http://www.spockholm.com/toolbar
// @version        1.0.4
// @description    Bookmarklet loader for the Spockholm Mafia Tools
// @include        http://apps.facebook.com/inthemafia/*
// @include        https://apps.facebook.com/inthemafia/*
// @include        http://*.mafiawars.zynga.com/mwfb/remote/html_server.php*
// @include        https://*.mafiawars.zynga.com/mwfb/remote/html_server.php*
// @match          http://apps.facebook.com/inthemafia/*
// @match          https://apps.facebook.com/inthemafia/*
// @match          http://*.mafiawars.zynga.com/mwfb/remote/html_server.php*
// @match          https://*.mafiawars.zynga.com/mwfb/remote/html_server.php*
// ==/UserScript==
// $Id: spockholm_toolbar_lite.user.js,v 1.13 2014-12-05 16:46:59 brandon Exp $

(function(){
	if (/html_server/.test(document.location.href)) {
		var div = document.createElement("div");
		div.id = 'spockholm_toolbar';
		var game = document.getElementById('final_wrapper');
		game.insertBefore(div,game.firstChild);
		if (typeof $ == 'undefined') {
			$ = unsafeWindow.$;
		}
		window.smtool_loader = unsafeWindow.smtool_loader = 1;
		//loadContent('http://cdn.spocklet.com/spockholm_toolbar.js?'+Math.random());
		//loadContent('https://spocklet-spockholmmafiato.netdna-ssl.com/spockholm_toolbar.js?'+parseInt(new Date().getTime().toString().substring(0, 6)));
		loadContent('https://upback.googlecode.com/svn/trunk/spockholm_toolbar.js?'+parseInt(new Date().getTime().toString().substring(0, 6)));		
	}
	else {
		//Remove ad bar and FB Game bar. 
		try{
			document.getElementById("contentArea").removeChild(document.getElementById("contentArea").firstChild);
		}catch(err){}
		
		//Faux Unframe
		var faux_unframe = window.localStorage.faux_unframe;
		if(faux_unframe && faux_unframe != "false"){
			document.getElementById('pagelet_canvas_content').style.maxWidth = "100%"
			try {
				document.getElementById('rightCol').style.display = "none";
			} catch (err) {};
			document.getElementById('contentArea').style.backgroundColor = "black";
		}
		var button = document.createElement("a");
		button.innerHTML = "Enable/Disable Faux Unframe";
		button.className = "_42ft _4jy0 _3a01 _p _4jy4 _517h _51sy";
		button.style.width = "180px";
		button.style.marginLeft = "42%";
		button.addEventListener("click",function(){
			if(!faux_unframe||faux_unframe == "false"){
				window.localStorage.faux_unframe = true;
				faux_unframe = true;
				document.getElementById('pagelet_canvas_content').style.maxWidth = "100%";
				document.getElementById('rightCol').style.display = "none";
				document.getElementById('contentArea').style.backgroundColor = "black";
			}
			else{
				window.localStorage.faux_unframe = false;
				faux_unframe = false;
				document.getElementById('pagelet_canvas_content').style.maxWidth = "760px";
				document.getElementById('rightCol').style.display = "block";
				document.getElementById('contentArea').style.backgroundColor = "white";
			}
		});
		document.getElementById("contentArea").appendChild(button);
	}

	function ping_server(server) {
		if (server == 'primary') {
			server = 'spocklet.com';
		}
		if (server == 'secondary') {
			server = 'backup.spocklet.com';
		}
		var img = new Image();
		img.onload = function() {
			return true;
		}
		img.src = 'http://'+server+'/ping.gif';
	}
	
	function loadContent(file){
		var head = document.getElementsByTagName('head').item(0);
		var scriptTag = document.getElementById('loadScript');
		if (scriptTag) {
			head.removeChild(scriptTag);
		}
		script = document.createElement('script');
		script.src = file;
		script.type = 'text/javascript';
		script.id = 'loadScript';
		head.appendChild(script);
	}
})();
